package h.d.bluetooth.visitor;

import h.d.bluetooth.visitor.common.VaE;
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;

/**
 * @author hdeom
 * @date 2014. 1. 15.
 *
 */
public class App extends Application{

	private static SharedPreferences mPreference;
	private static SharedPreferences.Editor mPreferenceEditor;
	private String PreferenceKey_FileName = "setting";


	public final static String DISCOVERABLE = "discoverable";
	public final static String SCAN_MODE = "scan_mode";
	public final static String SCAN_CYCLE = "scan_cycle";
	public final static String LOW_BETTERY = "low_bettery";
	public final static String LOW_BETTERY_VALUE = "low_bettery_value";

	/**
	 * @author hdeom
	 * @date 2014. 1. 15.
	 * @param
	 * @return
	 *
	 **/
	@Override
	public void onCreate() {
		super.onCreate();

		mPreference = getSharedPreferences(PreferenceKey_FileName , 0);
		mPreferenceEditor = mPreference.edit();

		VaE.VaEManager = new VaE();
	}


	//preference value load
	public static String getPreferenceValue(String preferenceKey, String defaultValue){
		return mPreference.getString(preferenceKey, defaultValue);
	}

	//preference default value
	public static String getPreferenceValue(String preferenceKey){
		String defaultValue = getDefaultValue(preferenceKey);
		return mPreference.getString(preferenceKey, defaultValue);
	}

	/**
	 * @author hdeom
	 * @date 2014. 1. 15.
	 * @param
	 * @return
	 *
	 **/
	private static String getDefaultValue(String key) {
		String ret = "";

		if(TextUtils.equals(key, DISCOVERABLE)){
			ret = "y";
		}else if(TextUtils.equals(key, SCAN_MODE)){
			ret = "y";
		}else if(TextUtils.equals(key, SCAN_CYCLE)){
			ret = "5";
		}else if(TextUtils.equals(key, LOW_BETTERY)){
			ret = "y";
		}else if(TextUtils.equals(key, LOW_BETTERY_VALUE)){
			ret = "30";
		}

		return ret;
	}


	//preference value save
	public static void setPreferenceValue(String preferenceKey, String value){
		mPreferenceEditor.putString(preferenceKey, value);
		mPreferenceEditor.commit();
	}

	//preference value save
	public static void setPreferenceValue(String preferenceKey, boolean value){
		mPreferenceEditor.putBoolean(preferenceKey, value);
		mPreferenceEditor.commit();
	}

}
